// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import {toolList} from "./handControl";
import gameData from "./gameData";
import portalMediator from "./portalMediator";
import AudioManage, {soundList} from "../framework/AudioManage";
import sceneMediator from "../framework/sceneMediator";
import Tool from "../framework/Tool";
import { SDKManager } from "./SDKManager/SDKManager";
import XFManager from "./XFManager";

// import AudioManage, {soundList} from "../resources/framework/AudioManage";

const {ccclass, property} = cc._decorator;

let sceneList = null;

const  ShaderEnum = cc.Enum({});

@ccclass
export default class endingMediator extends cc.Component {

    // @property({
    //     type: ShaderEnum,
    // })
    @property()
    sceneName : string = "";

    @property({
        displayName : "过关点"
    })
    passLevel : boolean = false;

    @property({displayName : "无尽模式"})
    isEndless :boolean = false;

    @property({displayName : "无尽模式2"})
    isEndless2 :boolean = false;

    @property({displayName : "无尽模式3"})
    isEndless3 :boolean = false;

    @property({displayName : "关卡模式"})
    levelModel : boolean = false;


    onBeginContact(contact, self, other) {
        if(other.node.group == "role"){
            if(this.isEndless){
                Tool.loadPrefab("prefabs/endlessWin",(res)=>{
                    let view =  cc.instantiate(res);
                    view.parent = cc.find("Canvas");
                })
            }else if(this.isEndless2){
                Tool.loadPrefab("prefabs/endlessWin",(res)=>{
                    let view =  cc.instantiate(res);
                    view.getComponent("endlessWin").setCallBack(true,true);
                    view.parent = cc.find("Canvas");
                })
            }else if(this.isEndless3){
                Tool.loadPrefab("prefabs/endlessWin",(res)=>{
                    let view =  cc.instantiate(res);
                    view.getComponent("endlessWin").setCallBack(true,true,true);
                    view.parent = cc.find("Canvas");
                })
            }else  if(this.passLevel){
                cc.game.emit("gameWin");
            }else{
                AudioManage.playSFX(soundList.switchRoom,false);
                // cc.director.loadScene(sceneList[this.sceneName]["name"]);
                if(this.levelModel){
                    cc.director.loadScene("sp" + this.sceneName);
                }else{
                    if(sceneMediator.curEnterLevel == 0){
                        cc.director.loadScene("game" + this.sceneName);
                    }else{
                        cc.director.loadScene("prince" + this.sceneName);
                    }
                }
            }
        }
    }
}
